#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 1e5 + 10;

int a[N];
int pre[N];

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	int res = 0;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		if(a[i] == 0) a[i] = -1;
		pre[i] = pre[i - 1] + a[i];
	}
	for(int l = 1; l <= n; l++){
		for(int r = l + res; r <= n; r++){ 
			if(pre[r] - pre[l - 1] == 0){
				res = max(res, r - l + 1);
			}
		}
	}
	cout << res << endl;
	return 0;
}